#!/bin/sh

# http://leadtosilverlining.blogspot.com/2019/01/setup-desktop-environment-on-google.html

set -ex


cat <<'EOF'

#!/bin/sh

Step 1: install dependencies

  sudo apt-get install gnome-shell ubuntu-gnome-desktop autocutsel tightvncserver gnome-core gnome-panel synaptic

  touch ~/.Xresources


Step 2: Setup VNC server

  To setup VNC server, run:

  $ vncserver


  You will require a password to access your desktops.

  Password: 
  Verify:   
  Would you like to enter a view-only password (y/n)? n
  xauth:  file /home/chunming/.Xauthority does not exist

  New 'X' desktop is multitask-gpu-asia:1

  Creating default startup script /home/chunming/.vnc/xstartup
  Starting applications specified in /home/chunming/.vnc/xstartup
  Log file is /home/chunming/.vnc/multitask-gpu-asia:1.log


Step 3: Modify VNC configuration
Modify the generated startup script /home/chunming/.vnc/xstartup to the same as below:


export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:$PATH

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
autocutsel -fork
xsetroot -solid grey
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:Unity"
export XDG_MENU_PREFIX="gnome-flashback-"
unset DBUS_SESSION_BUS_ADDRESS
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check --debug &



Step 5: Edit .bashrc file
Add a new command to~/.bashrc. It willl kill VNC session and then start a new one with indicated resolution.

function restart_vnc() {
        vncserver -kill :1
        vncserver -geometry "$1"
}


Step 6: Run VNC server with 1920x1080 resolution and test connection.

$ restart_vnc 1920x1080


Download VNC viewer: https://www.realvnc.com/en/connect/download/viewer/

You can connect to IP address with 5901 port of VM instance.

EOF
